package ch03.test;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.apache.log4j.Logger;

import java.lang.reflect.Method;

public class GuestMethodInterceptor implements MethodInterceptor {
    private Logger logger = Logger.getLogger(GuestMethodInterceptor.class);

    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        before();
        Object invoke = methodProxy.invokeSuper(proxy, args);
        after();
        return "总结:" + invoke;
    }

    public void before() {
        logger.debug("喝茶");
        logger.debug("聊天");
        logger.debug("吃饭");
    }

    public void after() {
        logger.debug("送客");
    }
}
